package com.pth.action;

import java.io.*;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.pth.model.Exam;
import com.pth.service.ExamService;

public class GetAjaxAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private int eid;
	private ExamService examService;
	private Exam exam;
	private String jftime;
	private String pxtime;
	private String pxaddr;
	private InputStream inputStream;  
	 
    public InputStream getResult(){  
          
        return inputStream;  
          
    }  

	public String getJftime() {
		return jftime;
	}

	public void setJftime(String jftime) {
		this.jftime = jftime;
	}

	public String getPxtime() {
		return pxtime;
	}

	public void setPxtime(String pxtime) {
		this.pxtime = pxtime;
	}

	public String getPxaddr() {
		return pxaddr;
	}

	public void setPxaddr(String pxaddr) {
		this.pxaddr = pxaddr;
	}

	public void setEid(int eid) {
		this.eid = eid;
	}

	public int getEid() {
		return eid;
	}
	
	
	@Override
	public String execute() throws Exception {
	
		exam=examService.getExamByEid(eid);
		Gson gson=new Gson();
		String result=gson.toJson(exam);
		// inputStream =new ByteArrayInputStream(result.getBytes("UTF-8"));
		HttpServletResponse resp=ServletActionContext.getResponse();
		HttpServletRequest req=ServletActionContext.getRequest();
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		PrintWriter out=resp.getWriter();
		out.println(result);
		out.flush();
		out.close();
		
		
		return SUCCESS;
		
	}

	public void setExamService(ExamService examService) {
		this.examService = examService;
	}

	public ExamService getExamService() {
		return examService;
	}

	public void setExam(Exam exam) {
		this.exam = exam;
	}

	public Exam getExam() {
		return exam;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public InputStream getInputStream() {
		return inputStream;
	}
	
	
}
